<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <title>会员列表</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
</head>
<body>
<div class="container">
    <!-- 显示错误信息 -->
    <c:if test="${not empty errorMsg}">
        <div class="error-message">
            <strong>错误：</strong> ${errorMsg}
        </div>
    </c:if>

    <h2>会员管理</h2>

    <!-- 返回管理员主页 -->
    <p><a href="${pageContext.request.contextPath}/adminHome.html">返回管理员主页</a></p>

    <!-- 新增会员表单 -->
    <form action="MemberServlet?action=add" method="post">
        <div class="form-group">
            <label>会员姓名：</label>
            <input type="text" name="memberName" required placeholder="请输入会员姓名">
        </div>
        <div class="form-group">
            <label>联系电话：</label>
            <input type="text" name="phone" required placeholder="请输入联系电话">
        </div>
        <button type="submit" class="btn btn-add">添加会员</button>
    </form>

    <!-- 会员列表展示 -->
    <h2>会员列表</h2>
    <c:if test="${not empty memberList}">
        <table>
            <thead>
            <tr>
                <th>会员 ID</th>
                <th>会员姓名</th>
                <th>联系电话</th>
                <th>积分</th>
                <th>会员等级</th>
                <th>折扣率</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach var="member" items="${memberList}">
                <tr>
                    <td>${member.memberId}</td>
                    <td>${member.memberName}</td>
                    <td>${member.phone}</td>
                    <td>${member.points}</td>
                    <td>${member.membershipLevel}</td>
                    <td>${member.discountRate}</td>
                    <td>
                        <a href="MemberServlet?action=delete&memberId=${member.memberId}"
                           class="btn btn-delete"
                           onclick="return confirm('确定删除该会员吗？')">删除</a>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </c:if>
    <c:if test="${empty memberList}">
        <p>暂无会员数据</p>
    </c:if>
</div>
</body>
</html>